#include "heibai_chessboard_cmd.h"
#include <string.h>
#include <stdio.h>

CHBChessBoardCmd::CHBChessBoardCmd()
{
	strcpy(m_data[0], "  1 2 3 4 5 6 7 8");
	strcpy(m_data[1], "1                ");
	strcpy(m_data[2], "2                ");
	strcpy(m_data[3], "3                ");
	strcpy(m_data[4], "4                ");
	strcpy(m_data[5], "5                ");
	strcpy(m_data[6], "6                ");
	strcpy(m_data[7], "7                ");
	strcpy(m_data[8], "8                ");
	strcpy(m_profile[0], "-------------------");
	strcpy(m_profile[1], "* play:, o play:");
	strcpy(m_profile[2], "");
}

void CHBChessBoardCmd::ShowBoard()
{
	int i;
	for(i = 0; i < 9; i++){
		printf("%s\n", m_data[i]);
	}
	for(i = 0; i < 3; i++){
		printf("%s\n", m_profile[i]);
	}
}

void CHBChessBoardCmd::PutChess(int x, int y, int user)
{
	char cchess = '+';
	if(user == USER1)
		cchess = '*';
	else if(user == USER2)
		cchess = 'o';
	m_data[y][2*x] = cchess;
}

void CHBChessBoardCmd::GetSignal(int &x, int &y)
{
	do{
		printf("x,y:");
		scanf("%d,%d", &x, &y);
		getchar();
	}while(x < 1 || x > 8 || y < 1 || y > 8);
}

void CHBChessBoardCmd::SetProfile(int type, int user1Chess, int user2Chess, int user)
{
	char cchess = '=';
	if(user == USER1)
		cchess = '*';
	else if(user == USER2)
		cchess = 'o';
	sprintf(m_profile[1], "* play:%d,o play:%d", user1Chess, user2Chess);
	if(type == HEIBAI_PRO_TYPE_END){
		sprintf(m_profile[2], "%c play win!", cchess);
	}else if(type == HEIBAI_PRO_TYPE_PLAY){
		sprintf(m_profile[2], "%c play", cchess);
	}
}
